package com.im.partchat.http.apiManager;

import com.im.partchat.constant.Constatnt;
import com.im.partchat.http.api.DownLoadApi;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

/**
 * Created by fzl on 2017/6/29 0029.
 * VersionCode: 1
 * Desc:
 */

public class DownApiManager {
    private static DownApiManager instance = null;
    private static final long DEFAULT_TIME_OUT = 30;
    private static Retrofit retrofit;

    private DownApiManager() {
    }
    public static DownLoadApi getInstance() {
        synchronized (DownApiManager.class) {
            if (instance == null) {
                instance = new DownApiManager();


                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                builder.connectTimeout(DEFAULT_TIME_OUT, TimeUnit.SECONDS);
                builder.readTimeout(DEFAULT_TIME_OUT, TimeUnit.SECONDS);
                builder.writeTimeout(DEFAULT_TIME_OUT, TimeUnit.SECONDS);

                OkHttpClient client = builder.build();
                Retrofit.Builder retrofitBuilder = new Retrofit.Builder();
                retrofit = retrofitBuilder.baseUrl(Constatnt.BASE_URL)
                        .client(client)
                        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                        .build();



            }
        }

        return retrofit.create(DownLoadApi.class);
    }



}
